<template>
  <div class="wrapper" ref="cont">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
  import BScroll from 'better-scroll'
  export default {
    name: "Scroll",
    props: {
      probeType: {
        type: Number,
        default: 0
      },
      pullUpLoad: {
        type: Boolean,
        default: false
      }
    },
    data(){
      return {
        scroll: null
      }
    },
    mounted() {
      this.scroll = new BScroll(this.$refs.cont, {
        click: true,
        probeType: this.probeType,
        pullUpLoad: this.pullUpLoad
      })

      if(this.probeType === 2 || this.probeType === 3){
        this.scroll.on('scroll', (pos) => {
          this.$emit('scrollEvent', pos)
        })
      }

      if(this.pullUpLoad){
        this.scroll.on('pullingUp', () => {
          this.$emit('pullUp')
        })
      }
    },
    methods: {
      scrollTo(x, y, time=300){
        this.scroll && this.scroll.scrollTo(x, y, time)
      },
      refresh(){
        console.log(111)
        this.scroll && this.scroll.refresh()
      },
      finishPullUp(){
        this.scroll && this.scroll.finishPullUp()
      },
      scrollToElement(element){
        console.log(444)
        this.scroll && this.scroll.scrollToElement(element, 200)
      }
    }
  }
</script>

<style scoped>

</style>